cmake_minimum_required(VERSION 3.10)

enable_testing()

# set the project name
project(GHSL-2021-1011-accountsservice VERSION 1.0.0 DESCRIPTION "Proof of concept exploit for GHSL-2021-1011: double-free in accountsservice")

# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(EPollLoop_DIR "${CMAKE_SOURCE_DIR}/EPollLoop")
set(DBusParse_DIR "${CMAKE_SOURCE_DIR}/DBusParse")

option(USE_SANITIZERS "Enable ASAN and UBSAN" OFF)

add_compile_options(-Wall -Wextra -pedantic -Werror)

if (USE_SANITIZERS)
  set(SANITIZER_FLAGS "-fsanitize=address,undefined")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_FLAGS}")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS}")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS}")
  set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${SANITIZER_FLAGS}")
endif()

add_subdirectory(DBusParse)
add_subdirectory(EPollLoop)
add_subdirectory(EPollLoopDBusHandler)

add_executable(poc poc.cpp)
target_link_libraries(poc PUBLIC DBusParse DBusParseUtils util)
target_include_directories(
        poc PRIVATE
        $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/DBusParse/include/DBusParse>)

add_executable(poc2 poc2.cpp)
target_link_libraries(poc2 PUBLIC DBusParse DBusParseUtils EPollLoop EPollLoopDBusHandler)
target_include_directories(
        poc2 PRIVATE
        $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/DBusParse/include/DBusParse>
        $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/EPollLoop/include/EPollLoop>
        $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/EPollLoopDBusHandler/include/EPollLoopDBusHandler>)

add_executable(poc3 poc3.cpp)
target_link_libraries(poc3 PUBLIC DBusParse DBusParseUtils EPollLoop EPollLoopDBusHandler)
target_include_directories(
        poc3 PRIVATE
        $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/DBusParse/include/DBusParse>
        $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/EPollLoop/include/EPollLoop>
        $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/EPollLoopDBusHandler/include/EPollLoopDBusHandler>)
